package com.lagou.controller;

import com.lagou.domain.Menu;
import com.lagou.domain.ResponseResult;
import com.lagou.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    @RequestMapping("/findAllMenu")
    public ResponseResult findAllMenu() {
        return new ResponseResult(true, 200, "success", menuService.findAllMenu());
    }

    @RequestMapping("/findMenuInfoById")
    public ResponseResult findMenuInfoById(Integer id) {
        Map<String, Object> map = new HashMap<>();
        List<Menu> subMenuListByPid = menuService.findSubMenuListByPid(-1);
        map.put("parentMenuList", subMenuListByPid);
        if (id == -1) {
            //add操作
            map.put("menuInfo", null);
            return new ResponseResult(true, 200, "success", map);
        } else {
            //修改操作
            map.put("menuInfo", menuService.findMenuById(id));
            return new ResponseResult(true, 200, "success", map);
        }
    }
}
